package com.huaxin.hxmoduleworkorder.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.huaxin.hxmoduleworkorder.common.enums.InspectionReadStatus;
import com.huaxin.hxmoduleworkorder.common.enums.InspectionSendStatus;
import com.huaxin.hxmoduleworkorder.dto.ResponseResult;
import com.huaxin.hxmoduleworkorder.dto.request.GetOrderNotificationInSystemByUserIdReqDTO;
import com.huaxin.hxmoduleworkorder.dto.request.OrderNotificationCreateReqDTO;
import com.huaxin.hxmoduleworkorder.models.OrderNotification;
import com.huaxin.hxmoduleworkorder.service.OrderNotificationService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@Tag(name = "工单通知")
@RestController
@RequiredArgsConstructor
@RequestMapping("/v1/workorder/orderNotification")
public class OrderNotificationController {
    private final OrderNotificationService orderNotificationService;

    @PostMapping("/create")
    @Operation(summary = "创建工单通知", description = "创建工单通知")
    public ResponseResult<Boolean> create(@RequestBody OrderNotificationCreateReqDTO in) {
        return ResponseResult.ok(orderNotificationService.create(in));
    }

    @PostMapping("/getOrderNotificationInSystemByUserId")
    @Operation(summary = "查询工单通知列表", description = "查询工单通知列表")
    public ResponseResult<Page<OrderNotification>> getOrderNotificationInSystemByUserId(@RequestBody GetOrderNotificationInSystemByUserIdReqDTO in) {
        return orderNotificationService.getOrderNotificationInSystemByUserId(in);
    }

    @GetMapping("/getOrderNotificationById")
    @Operation(summary = "获取工单通知详情", description = "获取工单通知详情")
    public ResponseResult<OrderNotification> getOrderNotificationById(@Parameter(description = "工单通知ID") @RequestParam(value = "id", required = true) String id) {
        return orderNotificationService.getOrderNotificationById(id);
    }

    @GetMapping("/updateOrderNotificationSendStatus")
    @Operation(summary = "更新工单通知发送状态", description = "更新工单通知发送状态")
    public boolean updateOrderNotificationSendStatus(@Parameter(description = "工单通知ID") @RequestParam(value = "id", required = true) String id,
                                                     @Parameter(description = "发送状态：pending/sent/failed") @RequestParam(value = "sendStatus", required = true) String sendStatus) {
        return orderNotificationService.updateOrderNotificationSendStatus(id, InspectionSendStatus.of(sendStatus));
    }
    
    @GetMapping("/updateOrderNotificationReadStatus")
    @Operation(summary = "更新工单通知阅读状态", description = "更新工单通知阅读状态")
    public boolean updateOrderNotificationReadStatus(@Parameter(description = "工单通知ID") @RequestParam(value = "id", required = true) String id,
                                                     @Parameter(description = "阅读状态：unread/read") @RequestParam(value = "readStatus", required = true) String readStatus) {
        return orderNotificationService.updateOrderNotificationReadStatus(id, InspectionReadStatus.of(readStatus));
    }
}
